#include "SpiPeripheral.h"
#include "spi.h"
#include "gpio.h"

SpiPeripheral::SpiPeripheral(SPI_TypeDef* SPIx)
{
    this->channel = SPIx;
}

SpiPeripheral::~SpiPeripheral()
{
    ;
}

void SpiPeripheral::begin(void)
{
    if(channel == SPI3)
        Board_SPI3_Init();
}

void SpiPeripheral::chipSelect(void)
{
    if(channel == SPI3)
        SPI3_CS_CLEARBIT();
}

void SpiPeripheral::chipRelease(void)
{
    if(channel == SPI3)
        SPI3_CS_SETBIT();
}

u8 SpiPeripheral::readAfterWrite(u8 data)
{
    if(channel == SPI3)
        return Board_SPI3_ReadWriteByte(data);
    else
        return 0;
}

